<script type="text/javascript">
    function printPage(id) {
        //alert('successfully');
        var html="<fieldset>";
        html+= document.getElementById(id).innerHTML;
        html+="</fieldset>";

        var printWin = window.open('','','left=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status =0');
        printWin.document.write(html);
        printWin.document.close();
        printWin.focus();
        printWin.print();
        printWin.close();

        var html="<html>";
        html+="<head>";
        html+="<style type='text/css'>.mytable{border:1px solid #ccc;}.mytable tr{background-color:#008000;color:#FFF;}</style>";
        html+="<link rel='Stylesheet' type='text/css' href='<?php echo base_url(); ?>bootstrap/css/bootstrap.css' media='print' />";
        html+="<link rel='Stylesheet' type='text/css' href='<?php echo base_url(); ?>bootstrap/css/bootstrap-responsive.css' media='print' />";
        html+="<link rel='Stylesheet' type='text/css' href='<?php echo base_url(); ?>bootstrap/css/style.css' media='print' />";
        html+="<link rel='Stylesheet' type='text/css' href='<?php echo base_url(); ?>bootstrap/css/demo_table_jui.css' media='print' />";
        html+="</head>";
        html+= document.getElementById(id).innerHTML;
        html+="</html>";
  
    }
</script>
<?php

echo '<fieldset id="year" style="border:1px solid #239DA9 ;margin: 0 auto;width:95%;height: auto; padding:20px;border-radius:5px;">';
echo '<div style="float:right; margin-right: 15px;">';
echo anchor('report/show_report', img('images/cancel.png'), array('title' => 'Back'));
echo '</div>';
?><div style=" height: 50px;  margin:10px;"><img src="<?php echo base_url(); ?>/images/login_logo.png" align="center"   alt="Print semester report" />
<?php
echo '<h1 style="color: #239DA9;
    font-family: verdana;
    font-size: 20px;
    font-style: italic;
    font-weight: bold;
    text-shadow: 1px 1px 1px #8483E1;
    margin-top:-50px;
    text-decoration: underline;
    text-align: center;">Leaving Report</h1></div>';
echo '<br/><div style="float:right;color:#239DA9;width:40%;text-align:right; margin-top:-10px;padding-bottom: 15px;">View Report For  Seaching:' . '<b style="color:red;">  &nbsp;' . date("Y") . '</b><br/>'; 
  
?>

To print this report, Click here<a href="#">
    <img src="<?php echo base_url(); ?>/images/print.png" align="center" onclick="return printPage('year');" id="image"  alt="Print semester report" title="Print semester report"/>
</a></div><?php


echo '<table width="1150px" cellspacing="0" cellpadding="0" border="1" style=" border: 1px solid #CCC;" >
              <tr>
                <th colspan="3"  style="color:#239DA9;height: 40px;">Staff information</th>
                <th  style="color:#239DA9;">Detail information of leaving</th>
                <th style="color:#239DA9;">Total</th>
                          
</tr>
              <tr style="text-align:center;color:#239DA9;height:25px;">
                <th >Staff_name</th>
                <th>Gender</th>
                <th>Department</th>
                 <th>
                        <table style="width:800px;"  cellpadding="0" cellspacing="0">
                            <tr style="color:#239DA9;">
                                <th style="height: 40px; ">Start_date</th>
                                <th>End_date</th>
                                <th>Annual</th>
                                <th>Catch_Up</th>
                                <th>Impossed</th>
                                <th>Personal</th>
                                <th>Special</th>
                                
                        </tr>
                         
                        </table></th>
                    <th>Sub_Total</th>
              </tr>';


foreach ($get_report_values->result() as $report) { //======================loop data from database as a row ================
    $staff_id = $report->staff_id;
    echo '<tr style="text-align:center;color:#000;font-weight: lighter;padding:4px;">
                  <td style="text-align:center;">' . $report->username . '</td>
                  <td style="text-align:center;">' . $report->emp_gender . '</td>
                  <td style="text-align:center;">' . $report->dept_name . '</td>
                  <td style="text-align:center;">';
    $dat_from = $this->input->post('s_date');
    $dat_to = $this->input->post('e_date');
    $this->db->select('*');
    $this->db->from('pnc_record');
    $this->db->where('start_date >=', $dat_from);
    $this->db->where('end_date <=', $dat_to);
    $this->db->where('staff_id', $staff_id);
    $get_report_value = $this->db->get();

    foreach ($get_report_value->result_array() as $subQuery) {
        ?>
        <table cellpadding="0" cellspacing="0"  style="text-align: center; width:800px;">
            <tr>
                <td style="width: 129px; height: 35px;"><?php echo $subQuery['start_date']; ?></td>
                <td style="width: 115px;"><?php echo $subQuery['end_date']; ?></td>
                <td style="width: 85px;"><?php
        if ($subQuery['lea_id'] == 1) {
            echo $subQuery['duration'];
        } else {
            echo ('&nbsp');
        }
        ?>
                </td>
                <td style="width: 120px;">
                    <?php
                    if ($subQuery['lea_id'] == 2) {
                        echo $subQuery['duration'];
                    } else {
                        echo ('&nbsp');
                    }
                    ?>
                </td>
                <td style="width: 119px;">
                    <?php
                    if ($subQuery['stl_id'] == 1) {
                        echo $subQuery['duration'];
                    } else {
                        echo ('&nbsp;');
                    }
                    ?>
                </td>
                <td style="width: 107px;">
                    <?php
                    if ($subQuery['stl_id'] == 2) {
                        echo $subQuery['duration'];
                    } else {
                        echo ('&nbsp;');
                    }
                    ?>
                </td>
                <td style="width: 89px;">
                    <?php
                    if ($subQuery['stl_id'] == 3) {
                        echo $subQuery['duration'];
                    } else {
                        echo ('&nbsp;');
                    }
                    ?>
                </td>

            </tr>

            
        </table>

        <?php
    }
    echo '</td>
                  <td>';
    $annul = 0;
    $catch_up = 0;
    foreach ($get_report_value->result_array() as $subQuery) {
        $type_id = $subQuery['lea_id'];
        $id = $subQuery ['duration'];

        if ($type_id == 1) {
            $annul = $id + $annul;
        } else if ($type_id == 2) {
            $catch_up = $id + $catch_up;
        }
        $totals = $annul + $catch_up;
    }echo '<p style="color:red; font-weight: bold;">'.$totals.'</p>';
    echo'
</td>
                  </tr>';
}
echo '</table>';
echo '</fieldset>';
?>